The present invention relates to computer systems and more particularly to implementing a run-time environment.
A dynamic run-time environment for a language such as JAVA(trademark) is responsible for managing memory for objects that are created and destroyed during the execution of a program. An object is an entity that encapsulates data and, in some languages, operations associated with the object. Since the encapsulated data is stored in memory, objects are associated with particular regions of memory that are allocated and deallocated by the dynamic run-time environment.
In general, all implementations of a language run-time environment are built upon a low-level substrate that provides proto-language services. These services may include memory management, method dispatching, operating system (or other encapsulating environment) services, and outcall mechanisms. Typically, the low-level substrate and a schema of the system classes belonging to the run-time environment are hand written in a systems programming language such as C or C++ as well as assembly language subroutines. Conventional techniques for implementing the low-level substrate services, however, suffer from several disadvantages, depending on the implementation language being used.
For example, if the low-level substrate is written in the C programming language and assembly language, the resulting code tends to be difficult to design and maintain in comparison with object-oriented programming languages. Use of an objected-oriented language like the C++ programming language, however, also suffers from disadvantages. In particular, C++ member functions (methods) are difficult to interface with generic C environmental code due to compiler name-mangling, and sometimes involve run-time overhead in method dispatching (i.e. invoking virtual member functions requires an indirection through a virtual table). Furthermore, C++ is less portable than C.
Therefore, there exists a need for a way to implement low-level substrate services that is portable, efficient, and compatible with generic environmental code while attaining benefits associated with object-oriented programming.
This and other needs are addressed by the present invention, in which a static, object-oriented meta-object system is provided for implementing a run-time environment. In particular, code is generated by the meta-object system that is compatible with a high-order systems programming language such as C. Since the meta-object system is object-oriented, the benefits of ease of design and maintenance associated with object-oriented programming are attained. Since meta-object system is static, each invoked method can be identified at compile-time, leading to efficient method dispatching. Finally, the meta-object system methods are translated into xe2x80x9cgeneric functionsxe2x80x9d in a portable systems programming language such as C, thereby facilitating linkage with environmental code.
A generic function is a function that dispatches on the types of one or more of its arguments. For example, a generic function foo (A, B) could dispatch on either the arguments A, B, or both. A generic function that dispatches on only one argument provides the semantics of a normal method call, but unlike C++ methods, generic functions can dispatch on a plurality of arguments.
Accordingly, one aspect of the invention pertains to a method and software for implementing a run-time environment, comprising the computer-implemented steps of: defining an object-oriented type system for a plurality of objects being associated with respective operations; accessing a description of a generic function specifying an operation to be invoked based on an argument; and generating high-order language instructions for receiving an object as the argument and invoking a corresponding operation based on a type of the object.
Another aspect of the invention involves a method and software for implementing a run-time environment with a meta-object system in which an object-oriented type system is defined, comprising the computer-implemented steps of: accessing a description of a generic function specifying an operation to be dispatched based on more than one argument; and generating high-order language instructions for more than one object as the arguments and dispatching a corresponding operation based on the types of the objects.
Still other objects and advantages of the present invention will become readily apparent from the following detailed description, simply by way of illustration of the best mode contemplated of carrying out the invention. As will be realized, the invention is capable of other and different embodiments, and its several details are capable of modifications in various obvious respects, all without departing from the invention. Accordingly, the drawing and description are to be regarded as illustrative in nature, and not as restrictive.